{% extends('layout.html') %}
{% block body %}
<section id="tabs-bar" class="tabsbar">
    <div class="container">
        <div class="row">
            <div class="col s12 m12">
                <ul class="tabs">
                    <li class="tab col s3 m3 l4 xl2"><a {% if tab=='1' %} class="active" {% endif %} href="#ips"
                            onclick="activeTab(1)">IPS/IDS</a></li>
                    <li class="tab col s3 m3 l4 xl2"><a {% if tab=='2' %} class="active" {% endif %}
                            href="#ips-whitelist" onclick="activeTab(2)">Whitelist</a></li>
                </ul>
            </div>
        </div>
    </div>
</section>
<section id="ips" class="section">
    <div class="container">
        <div class="row">
            <div class="col s12 m1"></div>
            <div class="col s12 m5">
                <div class="card-panel">
                    <h4 class="red-text light-3">Denial Of Service</h4>
                    <form action="/advanced/ips" method="POST">
                        <input type="hidden" name="tab" value="1">
                        <input type="hidden" name="dnx_ddos_update">
                        <div class="row">
                            <div class="input-field col s12 center">
                                Enabled
                                <div class="switch">
                                    <label>
                                        Off
                                        <input type="checkbox" {% if ips_settings['ddos']['enabled'] %}
                                            checked="checked"  {% endif %} name="ddos" onchange="this.form.submit()">
                                        <span class="lever"></span>
                                        On
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <input type="text" name="tcp_limit" class="validate"
                                    placeholder="{{ips_settings['ddos']['tcp']}}">
                                <label for="">TCP Source Limit (conns/sec) | Current:
                                    {{ips_settings['ddos']['tcp']}}</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <input type="text" name="udp_limit" class="validate"
                                    placeholder="{{ips_settings['ddos']['udp']}}">
                                <label for="">UDP Source Limit (unique/sec) | Current:
                                    {{ips_settings['ddos']['udp']}}</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <input type="text" name="icmp_limit" class="validate"
                                    placeholder="{{ips_settings['ddos']['icmp']}}">
                                <label for="">ICMP Source Limit (packets/sec) | Current:
                                    {{ips_settings['ddos']['icmp']}}</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12 m4"></div>
                            <div class="input-field col s12 m4">
                                {% if ips_settings['ddos_notify'] %}
                                <a class="waves-effect waves-light btn modal-trigger col s12" href="#ips-modal1"><i
                                        class="material-icons"></i>Update</a>
                                <div id="ips-modal1" class="modal">
                                    <div class="modal-content">
                                        <h5 class="red-text">Enabling DDOS Prevention will have a limited effect when
                                            there is no active NATs on WAN interface.</h5>
                                    </div>
                                    <div class="modal-footer">
                                        <button class="btn waves-effect waves-light">Continue</button>
                                        <a class="modal-close waves-effect waves-green btn-flat">Cancel</a>
                                    </div>
                                </div>
                                {% else %}
                                <button class="btn waves-effect waves-light col s12">
                                    <i class="material-icons"></i> Update
                                </button>
                                {% endif %}
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="col s12 m5">
                <div class="card-panel">
                    <h4 class="red-text light-3">General Settings</h4>
                    <form action="/advanced/ips" method="POST">
                        <input type="hidden" name="tab" value="1">
                        <input type="hidden" name="general_settings">
                        <div class="row">
                            <div class="input-field col s6 center">
                                IDS Mode
                                <div class="switch">
                                    <label>
                                        Off
                                        <input type="checkbox" {% if ips_settings['ids_mode'] %}
                                            checked="checked" {% endif %} name="ids_mode" value="enabled"
                                            onchange="this.form.submit()">
                                        <span class="lever"></span>
                                        On
                                    </label>
                                </div>
                            </div>
                            <div class="input-field col s6 left">
                                <select name="passive_block_length" onchange="this.form.submit()">
                                    <option value="0" {% if ips_settings['length']==0 %} selected {% endif %}
                                        >disabled</option>
                                    <option value="24" {% if ips_settings['length']==24 %} selected {% endif %}
                                        >24 hours</option>
                                    <option value="48" {% if ips_settings['length']==48 %} selected {% endif %}
                                        >48 hours</option>
                                    <option value="72" {% if ips_settings['length']==72 %} selected {% endif %}
                                        >72 hours</option>
                                </select>
                                <label>Passive Block</label>
                            </div>
                        </div>
                        <noscript>
                        <div class="row">
                            <div class="input-field col s4 m4 center"></div>
                            <div class="input-field col s4 m4 center">
                                <button class="btn waves-effect waves-light col s12">
                                    <i class="material-icons"></i> Update
                                </button>
                            </div>
                        </div>
                        </noscript>
                    </form>
                </div>
                <div class="card-panel">
                    <h4 class="red-text light-3">Port Scan</h4>
                    <form action="/advanced/ips" method="POST">
                        <input type="hidden" name="tab" value="1">
                        <input type="hidden" name="dnx_portscan_update">
                        <div class="row">
                            <div class="input-field col s6 center">
                                Enabled
                                <div class="switch">
                                    <label>
                                        Off
                                        <input type="checkbox" {% if ips_settings['port_scan']['enabled'] %}
                                            checked="checked" {% endif %} name="ps_settings" value="enabled"
                                            onchange="this.form.submit()">
                                        <span class="lever"></span>
                                        On
                                    </label>
                                </div>
                            </div>
                            <div class="input-field col s6 center">
                                Reject
                                <div class="switch">
                                    <label>
                                        Off
                                        {% if not ips_settings['port_scan']['enabled'] or ips_settings['ids_mode'] %}
                                        <input disabled type="checkbox">
                                        {% else %}
                                        <input type="checkbox" {% if ips_settings['port_scan']['reject'] %}
                                            checked="checked" {% endif %} name="ps_settings" value="reject"
                                            onchange="this.form.submit()">
                                        {% endif %}
                                        <span class="lever"></span>
                                        On
                                    </label>
                                </div>
                            </div>
                        </div>
                        <noscript>
                            <div class="row">
                                <div class="input-field col s12 m4"></div>
                                <div class="input-field col s12 m4">
                                    {% if ips_settings['ps_notify'] %}
                                    <a class="waves-effect waves-light btn modal-trigger col s12" href="#ips-modal2"><i
                                            class="material-icons"></i>Update</a>
                                    <div id="ips-modal2" class="modal">
                                        <div class="modal-content">
                                            <h5 class="red-text">Enabling PortScan Logging/Prevention will have no effect
                                                when there is no active NATs on WAN interface.</h5>
                                        </div>
                                        <div class="modal-footer">
                                            <button class="btn waves-effect waves-light">Continue</button>
                                            <a class="modal-close waves-effect waves-green btn-flat">Cancel</a>
                                        </div>
                                    </div>
                                    {% else %}
                                    <button class="btn waves-effect waves-light col s12">
                                        <i class="material-icons"></i> Update
                                    </button>
                                    {% endif %}
                                </div>
                            </div>
                        </noscript>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
<section id="ips-whitelist" class="section">
    <div class="container">
        <div class="row">
            <div class="col s12 m8">
                <div class="card-panel">
                    <h4 class="red-text">Current Whitelist</h4>
                    <table class="striped">
                        <thead>
                            <tr>
                                <th></th>
                                <th>IP Address</th>
                                <th>Name</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% if ips_settings['ip_whitelist'] %}
                            {% for ip_address, name in ips_settings['ip_whitelist'].items() %}
                            <tr>
                                <td>
                                    <a class="waves-effect waves-light btn modal-trigger"
                                        href="#ips-modal3-{{loop.index}}"><i class="material-icons">remove</i></a>
                                    <div id="ips-modal3-{{loop.index}}" class="modal">
                                        <div class="modal-content">
                                            <h5 class="red-text">Are you sure you want to remove this IPS Whitelist Rule?
                                            </h5>
                                        </div>
                                        <form action="/advanced/ips" method="POST">
                                            <div class="modal-footer">
                                                <button class="btn waves-effect waves-light">YES</button>
                                                <a class="modal-close waves-effect waves-green btn-flat">Cancel</a>
                                                <input type="hidden" name="tab" value="2">
                                                <input type="hidden" name="ips_wl_ip" value="{{ip_address}}">
                                                <input type="hidden" name="ips_wl_remove">
                                            </div>
                                        </form>
                                    </div>
                                </td>
                                <td>{{ip_address}}</td>
                                <td>{{name}}</td>
                            </tr>
                            {% endfor %}
                            {% else %}
                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                            {% endif %}
                        </tbody>
                    </table>
                    </form>
                </div>
            </div>
            <div class="col s12 m4">
                <div class="card-panel">
                    <h4 class="red-text light-3">Add IPS Whitelist</h4>
                    <form action="/advanced/ips" method="POST">
                        <input type="hidden" name="tab" value="2">
                        <div class="row">
                            <div class="input-field col s12">
                                <input type="text" name="ips_wl_ip" class="validate" placeholder="127.0.0.1" required>
                                <label for="">IP Address</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <input type="text" name="ips_wl_name" class="validate" placeholder=dns required>
                                <label for="">Name</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s4 m4">
                                <input type="hidden" name="ips_wl_add" value="ips_whitelist">
                                <button class="btn waves-effect waves-light col s12">
                                    <i class="material-icons"></i> Add
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="card-panel">
                    <h4 class="red-text light-3">Include DNS Servers</h4>
                    <form action="/advanced/ips" method="POST">
                        <input type="hidden" name="tab" value="2">
                        <input type="hidden" name="ips_wl_dns">
                        <div class="row">
                            <div class="input-field col s12 center">
                                DNS Servers
                                <div class="switch">
                                    <label>
                                        Disabled
                                        <input type="checkbox" {% if ips_settings['dns_server_whitelist'] %}
                                            checked="checked" {% endif %} name="dns_enabled" onchange="this.form.submit()">
                                        <span class="lever"></span>
                                        Enabled
                                    </label>
                                </div>
                            </div>
                        </div>
                        <noscript>
                            <div class="row">
                                <div class="input-field col s4 m4">
                                    <button class="btn waves-effect waves-light col s12">
                                        <i class="material-icons"></i> Update
                                    </button>
                                </div>
                            </div>
                        </noscript>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}